<?php
include 'test_header.php';

class test_user_info_update_process extends UnitTestCase{
	
	private $db ; 
	private $username ;

	function setUp() {

		//请求更新信息的用户名
		$this->username = 'j';

		$this->db = db_connect();

		$sql = "
CREATE TABLE IF NOT EXISTS `user` (
  `username` varchar(255) NOT NULL,
  `passwd` varchar(128) NOT NULL,
  `role` varchar(16) NOT NULL,
  `email` varchar(64) NOT NULL,
  `signup_time` varchar(64) DEFAULT NULL,
  `last_signin_time` varchar(64) DEFAULT NULL,
  `last_signin_ipadd` varchar(128) DEFAULT NULL,
  PRIMARY KEY (`username`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;";
		$res = $this->db->query( $sql );

		$sql="
INSERT INTO `user` (`username`, `passwd`, `role`, `email`, `signup_time`, `last_signin_time`, `last_signin_ipadd`) VALUES
('j', '363b122c528f54df4a0446b6bab05515', '0', 'old@old.com', '2010-06-04', '2010-06-05 16:04:49', '127.0.0.1')";

		$res = $this->db->query( $sql );

		$sql ="
CREATE TABLE IF NOT EXISTS `user_profile` (
  `username` varchar(255) NOT NULL,
  `nick` varchar(255) DEFAULT NULL,
  `sex` varchar(6) DEFAULT NULL,
  `location` varchar(1024) DEFAULT NULL,
  `motto` varchar(1024) DEFAULT NULL,
  PRIMARY KEY (`username`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
		";

	  	$res = $this->db->query( $sql );

		$sql = "
INSERT INTO `user_profile` (`username`, `nick`, `sex`, `location`, `motto`) VALUES
('j', 'j', 'male', 'suse', 'lzmyxjj');
" ;

		$res = $this->db->query( $sql );

	}
	function tearDown(){ 
		
		$sql = 'DROP TABLE `user`';
		$res = $this->db->query( $sql );
		$sql = 'DROP TABLE `user_profile`' ;
		$res = $this->db->query( $sql );
	}


	function test_update_email(){

		$db_obj_user = new db_obj_user( $this->db );
		$update_user_info_process = new update_user_info_process( $this->db , $this->username ) ; 

		$new_email = 'new@new.com';
		$this->assertTrue( $update_user_info_process->update_email( $new_email ) );

		$db_obj_user->load( 'username' , 'j' );
		$this->assertEqual( $db_obj_user->get('email') , $new_email );
	}

	function test_update_nick(){
		
		$db_obj_user_profile = new db_obj_user_profile( $this->db );
		$update_user_info_process = new update_user_info_process( $this->db , $this->username ) ; 

		$new_nick = 'newNick';
		$this->assertTrue( $update_user_info_process->update_nick( $new_nick ) );

		$db_obj_user_profile->load( 'username' , 'j' );
		$this->assertEqual( $db_obj_user_profile->get('nick') , $new_nick );		
	}

	function test_update_motto(){}
}
	

$test = new test_user_info_update_process();
$test->run( new HtmlReporter() );

